# 7. 字符串判断：从键盘输入一个字符串，判断该字符串是否可以被转换为一个有效的数字。(禁止使用Python自带方法完成)
str = input("请输入一个字符串：")
a = 0
b = 0
c = 0
m = len(str)
for i in range(0,m):
    n = ord(str[i])
    if n < 48 or n >57:
        a += 1
        if n == 46:
            b += 1
        if n == 45:
            c += 1
if b == 1 and ord(str[0]) != 46 and ord(str[m-1]) != 46:
    print("可以被转换为一个有效的数字")
elif c == 1 and ord(str[0]) == 45 and b == 0 and a != 1:
    print("可以被转换为一个有效的数字")
elif c == 1 and ord(str[0]) == 45 and b == 1 and ord(str[1]) != 46 and  ord(str[m-1]) != 46:
    print("可以被转换为一个有效的数字")
elif a == 0:
    print("可以被转换为一个有效的数字")
else:
    print("不能被转换为一个有效的数字")

# string=input("输入：")
# negative=0
# point=0
# isvalid=True
# for c in string:
#     code=ord(c)
#     if (code<48 and code !=45 and  code!=46) or code>57:
#         isvalid = False
#         break
#     elif code == 45:
#         negative += 1
#     elif code == 46:
#         point += 1
# if negative>1:isvalid = False
# if point>1:isvalid = False
# if negative == 1 and string[0] != '-':isvalid = False
# if string[0] == '-' and string[1] == '.':isvalid = False
# if string[0] == '.'and string[1] == '-':isvalid = False
# if isvalid:
#     print("有效")
# else:
#     print("无效")
